#!/bin/bash
#--------HEADER-------------------------------------------------------------------------|
#ÚLTIMA DATA DE MODIFICAÇÃO:
# 04/09/2017
#
#
#AUTOR:
# Jefferson Rocha <lrcjefferson@gmail.com
#
#
#PROGRAMA:
# dos (Desligar OS)
#
#
#SITE:
# Para mais scripts como esse visite o meu site:
# https://linuxutilitarios.github.io
#
#
#DESCRIÇÃO:
# Utilitario para desligar o sistema em segundos, minutos ou
# horas, não precisando programar no cron o comando halt por exemplo.
#
#
#RECOMENDAÇÃO:
# Utilize este programa em /usr/bin para deixar o comando global.
#
#
#MODO DE USO:
# Dê permissão de uso com chmod +x dos
# A sintaxe é muito fácil, bastando apenas rodar o comando como root:
# dos -t 10s
# Neste caso programamos o sistema para desligar em 10 segundos.
# Poderiamos simplesmente substituir o 's' de segundos no final por,
# 'm' de minutos ou 'h' de horas.
#
#
#LICENÇA:
# MIT
#
# Copyright (c) <2017> <Jefferson Rocha>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
#
#CHANGELOG:
#
#----------------------------------------------------------------------------------------|


#( VÁRIAVEIS GLOBAL do SCRIPT )-----------#
ROOT=$(id -u)
programa="dos"
#------------------------#



#( É ROOT? )---------#
if [[ $ROOT -ne 0 ]]; then
 echo "Favor logar como root para prosseguir"
 exit 126 
fi

#( Parametros gerais com Case )---------#
case $1 in


-v|--version)
 echo "Versão 1.0";;


-h|--help)
 echo "
GERAL

Execute o Script com o parametro em segundos, minutos ou hora's, exemplo:
 $programa -t 10s
Neste caso o sistema irá desligar em 10 segundos!

DESCRIÇÃO

	-h, --help
		Ver as informações do programa

	-v, --version
		Informaçãoes da versão

	-l, --license
		Licensa do programa

	-t, --time
		Executar em Segundo's,Minuto's, Hora's ou dia's, sintaxe: s,m,h,d
		desligar --time 2h
 ";;


-t|--time)
 sleep $2$3; halt >&- ;;



-l|--license)
 echo "
   Copyright (c) <2017> <Jefferson Rocha>

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software and associated documentation files the Software, to deal
   in the Software without restriction, including without limitation the rights
   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   copies of the Software, and to permit persons to whom the Software is
   furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   THE SOFTWARE.
" ;;


*)
 echo "Opção inválida, consulte: $programa --help para maiores informações " ;;

esac
